package com.gasolinator.a.app;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class GasolinatorChopperData
{

    private static String TAG = "GasolinatorChopperData";
    private static GasolinatorChopperData instance;
    String combustible;
    Integer distance;

    int favoritesSize = 0;
    ArrayList<GasolinatorStation> gasStations;
    Boolean publicOnly;
    int selectedPointIndex = -1;
    SharedPreferences sharedPrefs;
    GasolinatorStation localGasStation;



    public GasolinatorChopperData()
    {
        this.gasStations = new ArrayList();
    }

    public static GasolinatorChopperData getInstance(Context paramContext) throws JSONException {
        if (instance == null)
        {
            instance = new GasolinatorChopperData();
        }
        return instance;
    }

    public boolean processResponseString(JSONArray localJSONArray, boolean isTest) throws JSONException {

        this.gasStations.clear();
        this.selectedPointIndex = -1;
        if (localJSONArray.length()<0) {
            return false;
        }

        for (int x=0;x<localJSONArray.length();x++) {

            JSONObject localJSONObject = localJSONArray.getJSONObject(x);

            //"41.350083, 1.720944"
            String Mapa = localJSONObject.getString("Mapa");


            Double latF = Double.parseDouble(Mapa.split(",")[0]);
            Double lngF = Double.parseDouble(Mapa.split(",")[1]);

            int lat = (int) (latF * 1E6);
            int lng = (int) (lngF * 1E6);

            localGasStation = new GasolinatorStation();
            localGasStation.setLatitude(latF);
            localGasStation.setLongitude(lngF);

            localGasStation.setGasStationId(localJSONObject.getInt("GasolineraId"));
            String rotulo = localJSONObject.getString("Rotulo");
            localGasStation.setName(rotulo);
            localGasStation.setType(GasolinatorTypes.getResourceByName(rotulo));
            localGasStation.setAddress(localJSONObject.getString("Direccion"));
            localGasStation.setCity(localJSONObject.getString("Localidad"));
            localGasStation.setProvincia(localJSONObject.getString("Provincia"));
            localGasStation.setHorario(localJSONObject.getString("Horario"));
            localGasStation.setFecha(localJSONObject.getString("Fecha"));
            localGasStation.setIsPublic(localJSONObject.getString("Venta"));

            JSONObject localJSONObjectGas = localJSONObject.getJSONObject("PrecioActualizado");

            try { localGasStation.setGas95(Double.valueOf(localJSONObjectGas.getDouble("95")));
            } catch(JSONException je1) { }
            try { localGasStation.setGas97(Double.valueOf(localJSONObjectGas.getDouble("97")));
            } catch(JSONException je1) { }
            try { localGasStation.setGas98(Double.valueOf(localJSONObjectGas.getDouble("98")));
            } catch(JSONException je1) { }
            try { localGasStation.setGasoil(Double.valueOf(localJSONObjectGas.getDouble("dieselA")));
            } catch(JSONException je1) { }
            try { localGasStation.setGasoilm(Double.valueOf(localJSONObjectGas.getDouble("dieselNuevoA")));
            } catch(JSONException je1) { }
            try { localGasStation.setGasoilb(Double.valueOf(localJSONObjectGas.getDouble("dieselB")));
            } catch(JSONException je1) { }
            try { localGasStation.setGasoilc(Double.valueOf(localJSONObjectGas.getDouble("dieselC")));
            } catch(JSONException je1) { }
            try { localGasStation.setBiodiesel(Double.valueOf(localJSONObjectGas.getDouble("bioDiesel")));
            } catch(JSONException je1) { }

//            if (!isTest) {
//                GasolinatorPreferences gasolinatorPreferences = new GasolinatorPreferences(context);
//                localGasStation.setFavorite(gasolinatorPreferences.getIsFavorite(localGasStation.getGasStationId()));
//            }
            gasStations.add(localGasStation);

        }
        return true;
    }

    public String convertStreamToString(InputStream paramInputStream) throws IOException
    {
        if (paramInputStream == null) {
            return null;
        }

        StringBuilder builder =  new StringBuilder();
        try
        {
            InputStreamReader localInputStreamReader = new InputStreamReader(paramInputStream, "UTF-8");
            BufferedReader localBufferedReader = new BufferedReader(localInputStreamReader);
            String str1 = localBufferedReader.readLine();
            paramInputStream.close();
            builder = builder.append(str1);
        }
        catch (Exception e)
        {

        }
        finally
        {
            paramInputStream.close();
        }
        return builder.toString();

    }
    public void getDataFromServer(Context paramContext)
    {

        SharedPreferences localSharedPreferences = PreferenceManager.getDefaultSharedPreferences(paramContext);
        this.sharedPrefs = localSharedPreferences;
        Integer localInteger = Integer.valueOf(this.sharedPrefs.getString("distance", "20"));
        this.distance = localInteger;
        Boolean localBoolean = Boolean.valueOf(this.sharedPrefs.getBoolean("public_only", true));
        this.publicOnly = localBoolean;
        String str1 = this.sharedPrefs.getString("combustible", "diesel");
        this.combustible = str1;



//        String str2,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14,str15;
//
//        StringBuilder localStringBuilder12;
//        if (this.sharedPrefs.getBoolean("preferences_brand_0", true))
//        {
//            str2 = "0,";
//            String str3 = String.valueOf(str2);
//            StringBuilder localStringBuilder1 = new StringBuilder(str3);
//            if (!this.sharedPrefs.getBoolean("preferences_brand_1", true))str4 = "1,";
//            StringBuilder localStringBuilder2 = localStringBuilder1.append("1,");
//            if (!this.sharedPrefs.getBoolean("preferences_brand_2", true))str5 = "2,";
//            StringBuilder localStringBuilder3 = localStringBuilder2.append("2,");
//            if (!this.sharedPrefs.getBoolean("preferences_brand_3", true))str6 = "3,";
//            StringBuilder localStringBuilder4 = localStringBuilder3.append("3,");
//            if (!this.sharedPrefs.getBoolean("preferences_brand_4", true))str7 = "4,";
//            StringBuilder localStringBuilder5 = localStringBuilder4.append("4,");
//            if (!this.sharedPrefs.getBoolean("preferences_brand_5", true))str8 = "5,";
//            StringBuilder localStringBuilder6 = localStringBuilder5.append("5,");
//            if (!this.sharedPrefs.getBoolean("preferences_brand_6", true)) str9 = "6,";
//            StringBuilder localStringBuilder7 = localStringBuilder6.append("6,");
//            if (!this.sharedPrefs.getBoolean("preferences_brand_7", true))str10 = "7,";
//            StringBuilder localStringBuilder8 = localStringBuilder7.append("7,");
//            if (!this.sharedPrefs.getBoolean("preferences_brand_8", true))str11 = "8,";
//            StringBuilder localStringBuilder9 = localStringBuilder8.append("8,");
//            if (!this.sharedPrefs.getBoolean("preferences_brand_9", true))str12 = "9,";
//            StringBuilder localStringBuilder10 = localStringBuilder9.append("9,");
//            if (!this.sharedPrefs.getBoolean("preferences_brand_10", true))str13 = "10,";
//            StringBuilder localStringBuilder11 = localStringBuilder10.append("10,");
//            if (!this.sharedPrefs.getBoolean("preferences_brand_11", true)) str14 = "11,";
//            localStringBuilder12 = localStringBuilder11.append("11,");
//            if (!this.sharedPrefs.getBoolean("preferences_brand_12", true)) str15 = "12,";
//        }
//        for (String str15 = "12,"; ; str15 = "")
//        {
//            String str16 = str15;
//            this.typesString = str16;
//            if (this.typesString.length() > 0)
//            {
//                String str17 = this.typesString;
//                int j = this.typesString.length() - 1;
//                String str18 = str17.substring(0, j);
//                this.typesString = str18;
//            }
//            String str19 = TAG;
//            StringBuilder localStringBuilder13 = new StringBuilder("typesString=");
//            String str20 = this.typesString;
//            String str21 = str20;
//            int k = Log.d(str19, str21);
//            Thread localThread = new Thread(this);
//            this.thread = localThread;
//            this.thread.start();
//
//        }
    }

    public int getFavoritesSize()
    {
        return this.favoritesSize;
    }

    public GasolinatorStation getGasStation(int paramInt)
    {
        localGasStation = (GasolinatorStation)this.gasStations.get(paramInt);

        return localGasStation;
    }

    public Double getPrice(int paramInt)
    {
        GasolinatorStation localGasStation = (GasolinatorStation)this.gasStations.get(paramInt);
        String str = this.combustible;
        return Double.valueOf(localGasStation.getPrice(str));
    }



    public int getSelectedPointIndex()
    {
        return this.selectedPointIndex;
    }

    public int getSize()
    {
        return this.gasStations.size();
    }

    public void setCombustible(String paramString)
    {
        if (("gas95".equals(paramString)) || ("gas97".equals(paramString)) || ("gas98".equals(paramString)) || ("gasoil".equals(paramString)) || ("gasoilm".equals(paramString)) || ("gasoilb".equals(paramString)) || ("gasoilc".equals(paramString)) || ("biodiesel".equals(paramString)))
        {
            this.combustible = paramString;
            return;
        }
        this.combustible = "gasoil";
    }

    public void setSelectedPointIndex(int paramInt)
    {
        this.selectedPointIndex = paramInt;
    }


    public ArrayList<GasolinatorStation> getGasStations() {
        return gasStations;
    }
}

/* Location:           /home/fjhidalgo/Escritorio/gasolinator_flips/classes.dex.dex2jar.jar
 * Qualified Name:     com.gasolinator.a.app.GasolinatorChopperData
 * JD-Core Version:    0.6.0
 */